package qingke.hibernate;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.DetachedCriteria;

import qingke.hibernate.bean.Student;

public class CriteriaDemo {
public static void main(String[] args) {
	SessionFactory sf = new Configuration().configure().buildSessionFactory();
	Session session = sf.openSession();
	Criteria criteria = session.createCriteria(Student.class);
	List students = criteria.list();
	for(Object obj:students){
		System.out.println(obj);
	}
	
	DetachedCriteria c = DetachedCriteria.forClass(Student.class);
	Criteria cc = c.getExecutableCriteria(session);
	System.out.println("-------------");
	List stds = cc.list();
	for(Object obj :stds){
		System.out.println(obj);
	}
	System.out.println("-------------");
}
}
